﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CAGFIP.DataAccess.DataSetTableAdapters;
using CAGFIP.DataAccess;

namespace CAGFIP.Edicao
{
    public class RankingDAO : IRankingDAO
    {
        #region Fields

        private RankingTableAdapter rankingAdapter;
        private static readonly RankingDAO instance = new RankingDAO();

        #endregion
        
        #region Constructors

        private RankingDAO() { }

        #endregion

        #region Properties

        public static RankingDAO Instance
        {
            get { return instance; }
        }

        private RankingTableAdapter RankingAdapter
        {
            get { return this.rankingAdapter ?? (this.rankingAdapter = new RankingTableAdapter()); }
        }

        #endregion

        #region Methods

        public DataSet.RankingDataTable VisualizarRankingDataSet()
        {
            return RankingAdapter.VisualizarRankingDataSet();
        }

        public List<Ranking> VisualizarRanking()
        {
            List<Ranking> rankingList = new List<Ranking>();

            var ds = RankingAdapter.VisualizarRanking();

            foreach (CAGFIP.DataAccess.DataSet.RankingRow row in ds)
            {
                Ranking ranking = new Ranking(row.Dificuldade, row.Posicao, row.Nome, row.Pontuacao);
                rankingList.Add(ranking);
            }

            return rankingList;
        }

        public void AtualizarRanking(Ranking ranking)
        {
            RankingAdapter.AtualizarRanking(ranking.Nome, ranking.Pontuacao, ranking.Dificuldade, ranking.Posicao);
        }

        #endregion
    }
}
